package apache.openejb.message.driven.bean;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "RequestQueue")
})
public class HelloWorld implements MessageListener {       
    public void onMessage(Message message) {
        final TextMessage textMessage = (TextMessage) message;
        
        try {
            String hostname = InetAddress.getLocalHost().getHostName();
            final String txt = textMessage.getText();
            System.err.println(txt + ", and consumed by message driven bean at " + hostname);     
            
        } catch (JMSException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
